package com.shierke.Ume.ui.fragment.match

import ViewPagerAdapterLazyFragment
import android.app.AlertDialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import com.shierke.Ume.R
import com.shierke.Ume.ui.adapter.Match.HomeMatchAdapter
import kotlinx.android.synthetic.main.fragment_match.*
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.SnapHelper
import com.app.hubert.library.Controller
import com.app.hubert.library.NewbieGuide
import com.app.hubert.library.OnGuideChangedListener
import com.blankj.utilcode.util.ToastUtils
import com.shierke.Ume.util.click
import kotlinx.android.synthetic.main.lead_upload_more_image.*


/**
 * Create by Ybx
 * on 2020-10-12
 * Desribe:
 */
class MatchFragment : ViewPagerAdapterLazyFragment() {
    override fun onFragmentShow() {

    }

    override fun onFragmentHide() {
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)


        val linearLayoutManager = LinearLayoutManager(activity)
        linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL
        homeRecycle.layoutManager = linearLayoutManager
        val snapHelper = PagerSnapHelper()
        snapHelper.attachToRecyclerView(homeRecycle)

        val homeMatchAdapter = HomeMatchAdapter(initData())
        homeRecycle.adapter = homeMatchAdapter


        val builder = AlertDialog.Builder(activity)
        val view1 =
            LayoutInflater.from(activity).inflate(R.layout.lead_upload_more_image, null, false)
        val notNow = view1.findViewById<TextView>(R.id.notNow)
        val uploda = view1.findViewById<TextView>(R.id.upload)

        builder.setCancelable(false)

        builder.setView(view1)
        val create = builder.create()
        val window = create.window
        window!!.setBackgroundDrawable(ColorDrawable(0))
        notNow.click {
            create.dismiss()
        }

        uploda.click {
            create.dismiss()
        }


        val leadChangeImage =
            NewbieGuide.with(activity).setOnGuideChangedListener(object : OnGuideChangedListener {
                override fun onShowed(p0: Controller?) {

                }

                override fun onRemoved(p0: Controller?) {
                    create.show()

                }
            })
                .setEveryWhereCancelable(false)
                .setLayoutRes(R.layout.lead_change_image, R.id.next)
                .alwaysShow(true)
                .setLabel("lead_change_image")
                .build()


        NewbieGuide.with(activity).setOnGuideChangedListener(object : OnGuideChangedListener {
            override fun onShowed(p0: Controller?) {

            }

            override fun onRemoved(p0: Controller?) {
                leadChangeImage.show()
            }
        })
            .setEveryWhereCancelable(false)
            .setLayoutRes(R.layout.lead_slide, R.id.next)
            .alwaysShow(true)
            .setLabel("lead_slide")
            .build()
         //.show()


    }


    private fun initData(): ArrayList<ArrayList<Int>> {

        var zlyArr = arrayListOf(
            R.mipmap.home_zly1,
            R.mipmap.home_zly2,
            R.mipmap.home_zly3,
            R.mipmap.home_zly4
        )
        var zlsArr = arrayListOf(
            R.mipmap.home_zls,
            R.mipmap.home_zls2,
            R.mipmap.home_zls3,
            R.mipmap.home_zls4
        )
        var dlrbArr = arrayListOf(
            R.mipmap.home_dlrb,
            R.mipmap.home_dlrb1,
            R.mipmap.home_dlrb3,
            R.mipmap.home_dlrb4
        )

        return arrayListOf(zlyArr, zlsArr, dlrbArr)
    }


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        val view = LayoutInflater.from(activity).inflate(R.layout.fragment_match, null, false)

        return view

    }


}